简体   繁体   中英

JSF AJax - How to render the output from an URL

I am trying to render the output of an URL in the same page, using JSF / Ajax (a4j) and so far I am having no luck. BTW, I am using RichFaces 4.0. For example, if the User clicks a row in a Table (or just a button), I like to show a web page right below the Table, that is relevant to the row clicked. Is there a way I can get the relevant URL using a Backing Bean and invoke that URL using A4J Tags? I searched for such tags or sample code and so far I could not find any.

Thanks for your help.

Embedding the result of an external URL in your webpage can only neatly be done with help of a HTML <iframe> element.

So, this should do:

<h:form>
    <h:dataTable value="#{bean.websites}" var="website">
        <h:column>#{website.name}</h:column>
        <h:column>
            <h:commandButton value="show" action="#{bean.setWebsite(website)}">
                <f:ajax render=":website" />
            </h:commandButton>
        </h:column>
    </h:dataTable>
</h:form>
<h:panelGroup id="website">
    <iframe src="#{bean.website.url}"></iframe>
</h:panelGroup>

with

@ManagedBean
@ViewScoped
public class Bean {

    private List<Website> websites; // +getter
    private Website website; // +getter+setter

    // ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM