-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
76 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 22 additions & 18 deletions
40
src/main/java/cn/wujc/web/servlet/tags/easyui/grid/editor/ComboBoxEditorTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,43 @@ | ||
package cn.wujc.web.servlet.tags.easyui.grid.editor; | ||
|
||
import cn.wujc.web.servlet.tags.easyui.grid.EDataGridColumnTag; | ||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import cn.wujc.web.servlet.tags.easyui.form.ComboBoxTag; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.servlet.jsp.JspException; | ||
import javax.servlet.jsp.tagext.BodyContent; | ||
import javax.servlet.jsp.tagext.BodyTagSupport; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ComboBoxEditorTag extends BodyTagSupport { | ||
private static final Logger LOG = LoggerFactory.getLogger(ComboBoxEditorTag.class); | ||
private ComboBoxTag comboBox; | ||
|
||
public ComboBoxTag getComboBox() { | ||
return comboBox; | ||
} | ||
|
||
public void setComboBox(ComboBoxTag comboBox) { | ||
this.comboBox = comboBox; | ||
} | ||
private static final ObjectMapper MAPPER = new ObjectMapper().configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, false) | ||
.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); | ||
|
||
@Override | ||
public int doAfterBody() throws JspException { | ||
return SKIP_BODY; | ||
} | ||
|
||
@Override | ||
public int doEndTag() throws JspException { | ||
EDataGridColumnTag parent = (EDataGridColumnTag) findAncestorWithClass(this, EDataGridColumnTag.class); | ||
if (parent == null) { | ||
throw new JspException("ComboBoxEditorTag must in EDataGridColumnTag"); | ||
} | ||
String comboBox = bodyContent.getString(); | ||
Map<String, Object> editor = new HashMap<>(); | ||
editor.put("type", "combobox"); | ||
try { | ||
pageContext.getOut().print(new ObjectMapper().writeValueAsString(comboBox)); | ||
editor.put("options", MAPPER.readTree(comboBox)); | ||
} catch (IOException e) { | ||
throw new JspException(e); | ||
} | ||
try { | ||
parent.setEditor(MAPPER.writeValueAsString(editor)); | ||
} catch (JsonProcessingException e) { | ||
LOG.error("", e); | ||
} | ||
return EVAL_PAGE; | ||
return SKIP_BODY; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters