0

I'm going to make this as short as i can:

I have a sjt:tree widget on my page that is being refreshed from jquery code. I need that the jsp form where is located tree could be sent to the Struts2 Action when the tree is reloaded.

JSP CODE:


<s:form id="formToSend" name="formToSend" theme="simple" cssClass="yform">

<s:hidden id="instSelected" name="instSelected"/>   
<s:textfield id="inst" name="inst" theme="simple" style="width:85%" onblur="addHiddenValue()"/>

<s:url var="treeDataUrl" action="loadInstTree" namespace="/tree"/>
    <sjt:tree
    id="jsonTree"
    href="%{treeDataUrl}"
    onClickTopics="treeClickedProp"
    formIds="formToSend"
    jstreetheme="apple"
/>
</form>

JS Function:

function addHiddenValue() {

    var tmp= $('#inst').val();

    $('#instSelected').val(tmp);
    $('#inst').val('');     
    $('#jsonTree').jstree("refresh");

}

Struts.xml

<action name="loadInstTree"
            class="es.nstmt.action.ReloadTreeAction"
method="loadInstTree">
    <result type="json">
        <param name="root">nodes</param>
    </result>
</action>   

ReloadTreeAction.java


public class ReloadTreeAction extends ActionSupport {

    private String instSelected;

    private List<TreeNode> nodes = new ArrayList<TreeNode>();

    public String loadInstTree() {

        final List<TreeNode> org = new ArrayList<TreeNode>();

        if (!("".equals(instSelected)) && (instSelected!= null)) {
            final TreeNode node = new TreeNode();
            node.setId(instSelected);
            node.setIcon("ui-icon-document");
            node.setTitle(instSelected);
            node.setState(TreeNode.NODE_STATE_OPEN);
            org.add(node);
        }

        final TreeNode node = new TreeNode();
        node.setId("Root");
        node.setIcon("ui-icon-document");
        node.setTitle("INST");
        node.setState(TreeNode.NODE_STATE_OPEN);
        node.setChildren(org);

        nodes.add(node);

        return SUCCESS;
    }

    public List<TreeNode> getNodes() {
        return nodes;
    }

    public void setNodes(final List<TreeNode> nodes) {
        this.nodes = nodes;
    }

    public String getInstSelected() {
        return instSelected;
    }

    public void setInstSelected(final String instSelected) {
        this.instSelected= instSelected;
    }

}


The tree is being realoade correctly but the value of the variable instSelected in the Java code is always null no mather what method of reloading the tree I use. I also tried defining a reloadTopics inside the sjt:tree which could be called from the js code making a "publish" but that method only results in an infinite loop of the addHiddenValue function.

Any help will be much appreciated. Thank you all in advance.

Darkcloud
  • 33
  • 1
  • 7
  • You've verified that the value in `$('#instSelected')` is correct before the refresh in `addHiddenValue`? – Dave Newton Jun 05 '19 at 14:27
  • Why don't you think about what happens when you submit the form. See https://stackoverflow.com/a/22478386/573032 – Roman C Jun 05 '19 at 19:51

0 Answers0