从p:commandButton

时间:2016-08-02 11:33:32

标签: jsf primefaces

我有一个p:dataTable,其中每行有一个p:commondButton和一个h:outputText来显示项目的名称。 点击p:commandButton即可调用anfrageErfassenModel.applyProjekt() actionListener 更新p:inputText anfrageErfassenModel.anfrage.name中的值。

JSF页面 - anfrageErfassen.xhtml:

<h:form id="formAnfrageErfassen">

    <p:panelGrid columns="3" id="anfrage">
        <p:outputLabel for="name" value="#{bundle['anfrage.name']}"/>
        <p:inputText id="name" value="#{anfrageErfassenModel.anfrage.name}" required="true" />
        <p:message for="name" id="message4name" display="text"/>
    </p:panelGrid>

    <p:dataTable var="projekt" ...>
        <p:column>
            <p:commandButton icon="fa fa-check"
                title="Apply Project"
                update=":formAnfrageErfassen:anfrage"
                immediate="true"
                actionListener="#{anfrageErfassenModel.applyProjekt(projekt)}"/>
        </p:column>
        <p:column>
            <h:outputText value="#{projekt.name}"/>
        </p:column>
    </p:dataTable>
</h:form>

Bean - AnfrageErfassenModel.java:

@Named
@ViewScoped
public class AnfrageErfassenModel implements Serializable {

    private Anfrage anfrage; // with getter / setter

    public void applyProjekt(final Projekt projekt) {
        logger.entry(projekt);
        anfrage = anfrageRestClient.create();
        anfrage.setName(projekt.getName()); // take name from projekt
        logger.debug("anfrage.name=" + anfrage.getName());
        logger.exit();
    }       
}

actionListener调用anfrage.setName(projekt.getName()),这会导致模型的值按预期设置 - &GT;但p:inputText未更新!

我知道immediate="true"意味着,APPLY_REQUEST_VALUES阶段后面是RENDER_RESPONSE阶段!

我必须做什么才能使用模型的当前值更新inputText字段的值? 使用p:outputText代替p:inputText有效,但我需要inputText,因为该字段必须由用户编辑!

我在WildFly 10.0.0.Final上使用Primefaces 6.0。

谢谢和问候, 赖

1 个答案:

答案 0 :(得分:0)

感谢@Kukeltje - 将DECLARE @cats VARCHAR(255); DECLARE curs CURSOR FOR SELECT cats FROM ( SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) RN FROM Import) Z CROSS APPLY ( VALUES ([Main Category], 1) , ([Sub Category 1], 2) , ([Sub Category 2], 3)) S(cats,lvl) LEFT JOIN Template T ON T.Category = S.cats WHERE S.cats IS NOT NULL AND T.Category IS NULL GROUP BY cats ORDER BY MIN(lvl); -- main cats first, then subcat1, then subcat2 OPEN curs; FETCH NEXT FROM curs INTO @cats; WHILE @@FETCH_STATUS = 0 BEGIN INSERT Template(Category) VALUES (@cats); FETCH NEXT FROM curs INTO @cats; END CLOSE curs; DEALLOCATE curs; 添加到commandButton解决了这个问题!

相关问题