0
votes

I need to make some save action on h:selectonemenu. When it's value change then it should save this value, but without page refresh (so without submit).

Unfortunatelly I must work with jsf 1.2. After some research I've found that it can be done with a4j:support, however I have no idea how to include it into my project. Do I need to download some old richfaces libraries ? (as i know richfaces 4 doesnt support jsp syntax). Or does exists some other way to achieve this goal ??

1

1 Answers

1
votes

1. You could use Richfaces 3.3.4.Final (downaload here).

This is way you should include, register and use libraries in a project. Notice:

A JSF application with RichFaces assumes that the following JARs are available in the project: commons-beanutils-1.7.0.jar, commons-collections-3.2.jar, commons-digester-1.8.jar, commons-logging-1.0.4.jar, jhighlight-1.0.jar.

Example (from developer guide) for your case:

<h:form id="planetsForm">
<h:outputLabel value="Select the planet:" for="planets" />
<h:selectOneMenu id="planets" value="#{planetsMoons.currentPlanet}" valueChangeListener="#{planetsMoons.planetChanged}">
    <f:selectItems value="#{planetsMoons.planetsList}" />
    <a4j:support event="onchange" reRender="moons" />
</h:selectOneMenu>
<h:dataTable id="moons" value="#{planetsMoons.moonsList}" var="item">
    <h:column>
        <h:outputText value="#{item}"/>
    </h:column>
</h:dataTable>

2. Example of other solution:

You could use jQuery.ajax() with custom servlet.

JS:

$.ajax({
        type: 'GET',
        url: '/app/customservlet.jsf?value=' + selectOneValue; //selected value
});

Servlet:

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res) {     
    String selectOneValue = req.getParameter("value");      
    //do something
}