How to get selected value to do some stuff such as create a variable using j:set

config.jelly:

<f:entry title="Fruits">
  <f:select field="fruit" />
</f:entry>

Java source code:

public ListBoxModel doFillFruitItems() {
    return new ListBoxModel(
        new ListBoxModel.Option("Apple"),
        new ListBoxModel.Option("Banana")
    );
}

I want to get selected value to do some stuff such as create a variable using j:set such as :

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
    <f:entry title="Fruits">
      <f:select field="fruit" />
    </f:entry>
    <j:set var="tmp" value="${fruit}"/>
    <f:textbox value="${tmp}"/>
</j:jelly>

But tmp variable is always null.

I want to tmp variable is the selected value Thanks.

You can’t do this in jelly. A jelly file is rendered into html on server side when the page is loaded. When you want to react to changes to the select fruit you have to do this in javascript.

Thanks for your comment, I also tried to use JavaScript, but in my mind, I need to do some stuff because I would use data binding for that, if I used JavaScript then it could not reach my purpose.

f:select looks like this:

  <j:set var="value" value="${attrs.value ?: instance[attrs.field] ?: attrs.default}" />
  <div class="jenkins-select" data-readonly="${readOnlyMode}">
    <m:select xmlns:m="jelly:hudson.util.jelly.MorphTagLibrary"
              class="jenkins-select__input ${attrs.checkUrl!=null?'validated':''} select ${attrs.clazz}"
              name="${attrs.name ?: '_.'+attrs.field}"
              value="${value}"
              ATTRIBUTES="${attrs}" EXCEPT="field clazz">
      <j:if test="${value!=null}">
        <option value="${value}">${value}</option>
      </j:if>
    </m:select>
  </div>

So it sets a variable value that might contain what you want. Though I’m not sure if the variable still exists later on. Also it might contain null in case the jelly is called during creation of something new (e.g. the config page of a job that is opened after selecting New Item)

<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
    <f:entry title="Fruits">
      <f:select field="fruit" />
    </f:entry>
    <j:set var="tmp" value="${value}"/>
    <f:textbox value="${tmp}"/>
</j:jelly>

Sorry for the late response. But I applied your suggestion, but the value that was given is the last value of the list. If we have 2 f:select , then the second one could get the value of f:select previous to show it by using doFillXyzItems(@QueryParameter ) , so can we do that with for f:repeatable, to full fill items from backend Java with @QueryParameter ?

f:repeatable is used to render a field several times, not to fill a single select.

to repeat myself, jelly code is evaluated on the server side when the page is rendered. The doFillXYZ methods are called via javascript so the select can dynamically react to changes of other fields (Select [Jenkins])
You can interact with the backend from javascript, e.g. by implementing a javascript proxy (see JavaScript Proxy [Jenkins]) or by implementing some doSomething method that is annotated with @POST and the using fetch(url,...) in javascript to call that method