How to load data by submitting value in React app
In my react and spring-boot application, I have 3 drop-down menus and a submit button. Once button click, it takes the value from the drop-down and sends the request to the controller and fetch DB values and finally display on a different page.
I tried following, but it was not successful. How to solve this issue?
return (
<form onSubmit={this.handleSubmit}>
<div className="persent-one">
<i className="fa fa fa-caret-down" aria-hidden="true"></i>
<select className="textboxstyle" onChange={this.changeBrandLOV}><option value='-1'>Select Brand</option><option value ='0'>ALL</option>{optionItems}</select>
</div>
<div className="persent-one">
<i className="fa fa-caret-down" aria-hidden="true"></i>
<select className="textboxstyle" onChange={this.changeFamilyLOV}><option value='-1'>Select Family</option><option value ='0'>ALL</option>{familyOptionItems}</select>
</div>
<div className="persent-one">
<i className="fa fa fa-caret-down" aria-hidden="true"></i>
<select className="textboxstyle"><option key='-1'>Select Model</option><option key='0'>ALL</option>{modelOptionItems}</select>
</div>
<div className="persent-one less-btn">
<input type="submit" name="submit" value="Search" className="btn btn-info cst-btn" id="srch"/>
</div>
</div>
function
handleSubmit(event) {
event.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
const searchRequest = Object.assign({}, values);
searchModes(searchRequest,0,50)
.then(response => {
localStorage.setItem(ACCESS_TOKEN, response.accessToken);
}).catch(error => {
if(error.status === 401) {
notification.error({
message: 'Polling App',
description: 'Your search selections are incorrect. Please try again!'
});
} else {
notification.error({
message: 'Polling App',
description: error.message || 'Sorry! Something went wrong. Please try again!'
});
}
});
}
});
}
function
export function searchModes(searchRequest,page, size) {
page = page || 0;
size = size || POLL_LIST_SIZE;
return request({
url: API_BASE_URL + "/models?page=" + page + "&size=" + size,
method: 'GET'
});
}
In Controller class
@RestController
@RequestMapping("/api/models")
public class ModelController {
@GetMapping
public PagedResponse<Model> getModels(@CurrentUser UserPrincipal currentUser,
@RequestParam(value = "page", defaultValue = AppConstants.DEFAULT_PAGE_NUMBER) int page,
@RequestParam(value = "size", defaultValue = AppConstants.DEFAULT_PAGE_SIZE) int size) {
return modelService.getAllModels(currentUser, page, size);
}
error:
java spring reactjs spring-boot
add a comment |
In my react and spring-boot application, I have 3 drop-down menus and a submit button. Once button click, it takes the value from the drop-down and sends the request to the controller and fetch DB values and finally display on a different page.
I tried following, but it was not successful. How to solve this issue?
return (
<form onSubmit={this.handleSubmit}>
<div className="persent-one">
<i className="fa fa fa-caret-down" aria-hidden="true"></i>
<select className="textboxstyle" onChange={this.changeBrandLOV}><option value='-1'>Select Brand</option><option value ='0'>ALL</option>{optionItems}</select>
</div>
<div className="persent-one">
<i className="fa fa-caret-down" aria-hidden="true"></i>
<select className="textboxstyle" onChange={this.changeFamilyLOV}><option value='-1'>Select Family</option><option value ='0'>ALL</option>{familyOptionItems}</select>
</div>
<div className="persent-one">
<i className="fa fa fa-caret-down" aria-hidden="true"></i>
<select className="textboxstyle"><option key='-1'>Select Model</option><option key='0'>ALL</option>{modelOptionItems}</select>
</div>
<div className="persent-one less-btn">
<input type="submit" name="submit" value="Search" className="btn btn-info cst-btn" id="srch"/>
</div>
</div>
function
handleSubmit(event) {
event.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
const searchRequest = Object.assign({}, values);
searchModes(searchRequest,0,50)
.then(response => {
localStorage.setItem(ACCESS_TOKEN, response.accessToken);
}).catch(error => {
if(error.status === 401) {
notification.error({
message: 'Polling App',
description: 'Your search selections are incorrect. Please try again!'
});
} else {
notification.error({
message: 'Polling App',
description: error.message || 'Sorry! Something went wrong. Please try again!'
});
}
});
}
});
}
function
export function searchModes(searchRequest,page, size) {
page = page || 0;
size = size || POLL_LIST_SIZE;
return request({
url: API_BASE_URL + "/models?page=" + page + "&size=" + size,
method: 'GET'
});
}
In Controller class
@RestController
@RequestMapping("/api/models")
public class ModelController {
@GetMapping
public PagedResponse<Model> getModels(@CurrentUser UserPrincipal currentUser,
@RequestParam(value = "page", defaultValue = AppConstants.DEFAULT_PAGE_NUMBER) int page,
@RequestParam(value = "size", defaultValue = AppConstants.DEFAULT_PAGE_SIZE) int size) {
return modelService.getAllModels(currentUser, page, size);
}
error:
java spring reactjs spring-boot
1
Do you know where it is failing? Does it manage to send the request? Is it just failing to display the results? Any log outputs from the web browser or client?
– Cameron Downer
Nov 24 '18 at 16:15
yes, it gives error here. 256 | 257 | handleSubmit(event) { 258 | event.preventDefault(); > 259 | this.props.form.validateFields((err, values) => { 260 | if (!err) { 261 | const searchRequest = Object.assign({}, values); 262 | searchModes(0,50)
– chk.buddi
Nov 24 '18 at 16:18
That error isn't making a lot of sense to me. Are you sure that's the full & correct output? Add it to your question if it helps with formatting.
– Cameron Downer
Nov 24 '18 at 16:46
Hi @CameronDowner, I added the error page that displayed when clicking the button
– chk.buddi
Nov 24 '18 at 16:50
The error you're getting isn't to do with the request. You are trying to callthis.props.form.validateFields
butthis.props.form
doesn't exist. You need to look into where you expect theform
prop to come from.I think this question is too broad and I'm going to vote to close, but ask another question if you have a more specific issue
– Cameron Downer
Nov 24 '18 at 17:05
add a comment |
In my react and spring-boot application, I have 3 drop-down menus and a submit button. Once button click, it takes the value from the drop-down and sends the request to the controller and fetch DB values and finally display on a different page.
I tried following, but it was not successful. How to solve this issue?
return (
<form onSubmit={this.handleSubmit}>
<div className="persent-one">
<i className="fa fa fa-caret-down" aria-hidden="true"></i>
<select className="textboxstyle" onChange={this.changeBrandLOV}><option value='-1'>Select Brand</option><option value ='0'>ALL</option>{optionItems}</select>
</div>
<div className="persent-one">
<i className="fa fa-caret-down" aria-hidden="true"></i>
<select className="textboxstyle" onChange={this.changeFamilyLOV}><option value='-1'>Select Family</option><option value ='0'>ALL</option>{familyOptionItems}</select>
</div>
<div className="persent-one">
<i className="fa fa fa-caret-down" aria-hidden="true"></i>
<select className="textboxstyle"><option key='-1'>Select Model</option><option key='0'>ALL</option>{modelOptionItems}</select>
</div>
<div className="persent-one less-btn">
<input type="submit" name="submit" value="Search" className="btn btn-info cst-btn" id="srch"/>
</div>
</div>
function
handleSubmit(event) {
event.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
const searchRequest = Object.assign({}, values);
searchModes(searchRequest,0,50)
.then(response => {
localStorage.setItem(ACCESS_TOKEN, response.accessToken);
}).catch(error => {
if(error.status === 401) {
notification.error({
message: 'Polling App',
description: 'Your search selections are incorrect. Please try again!'
});
} else {
notification.error({
message: 'Polling App',
description: error.message || 'Sorry! Something went wrong. Please try again!'
});
}
});
}
});
}
function
export function searchModes(searchRequest,page, size) {
page = page || 0;
size = size || POLL_LIST_SIZE;
return request({
url: API_BASE_URL + "/models?page=" + page + "&size=" + size,
method: 'GET'
});
}
In Controller class
@RestController
@RequestMapping("/api/models")
public class ModelController {
@GetMapping
public PagedResponse<Model> getModels(@CurrentUser UserPrincipal currentUser,
@RequestParam(value = "page", defaultValue = AppConstants.DEFAULT_PAGE_NUMBER) int page,
@RequestParam(value = "size", defaultValue = AppConstants.DEFAULT_PAGE_SIZE) int size) {
return modelService.getAllModels(currentUser, page, size);
}
error:
java spring reactjs spring-boot
In my react and spring-boot application, I have 3 drop-down menus and a submit button. Once button click, it takes the value from the drop-down and sends the request to the controller and fetch DB values and finally display on a different page.
I tried following, but it was not successful. How to solve this issue?
return (
<form onSubmit={this.handleSubmit}>
<div className="persent-one">
<i className="fa fa fa-caret-down" aria-hidden="true"></i>
<select className="textboxstyle" onChange={this.changeBrandLOV}><option value='-1'>Select Brand</option><option value ='0'>ALL</option>{optionItems}</select>
</div>
<div className="persent-one">
<i className="fa fa-caret-down" aria-hidden="true"></i>
<select className="textboxstyle" onChange={this.changeFamilyLOV}><option value='-1'>Select Family</option><option value ='0'>ALL</option>{familyOptionItems}</select>
</div>
<div className="persent-one">
<i className="fa fa fa-caret-down" aria-hidden="true"></i>
<select className="textboxstyle"><option key='-1'>Select Model</option><option key='0'>ALL</option>{modelOptionItems}</select>
</div>
<div className="persent-one less-btn">
<input type="submit" name="submit" value="Search" className="btn btn-info cst-btn" id="srch"/>
</div>
</div>
function
handleSubmit(event) {
event.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
const searchRequest = Object.assign({}, values);
searchModes(searchRequest,0,50)
.then(response => {
localStorage.setItem(ACCESS_TOKEN, response.accessToken);
}).catch(error => {
if(error.status === 401) {
notification.error({
message: 'Polling App',
description: 'Your search selections are incorrect. Please try again!'
});
} else {
notification.error({
message: 'Polling App',
description: error.message || 'Sorry! Something went wrong. Please try again!'
});
}
});
}
});
}
function
export function searchModes(searchRequest,page, size) {
page = page || 0;
size = size || POLL_LIST_SIZE;
return request({
url: API_BASE_URL + "/models?page=" + page + "&size=" + size,
method: 'GET'
});
}
In Controller class
@RestController
@RequestMapping("/api/models")
public class ModelController {
@GetMapping
public PagedResponse<Model> getModels(@CurrentUser UserPrincipal currentUser,
@RequestParam(value = "page", defaultValue = AppConstants.DEFAULT_PAGE_NUMBER) int page,
@RequestParam(value = "size", defaultValue = AppConstants.DEFAULT_PAGE_SIZE) int size) {
return modelService.getAllModels(currentUser, page, size);
}
error:
java spring reactjs spring-boot
java spring reactjs spring-boot
edited Nov 24 '18 at 16:48
chk.buddi
asked Nov 24 '18 at 14:23
chk.buddichk.buddi
10912
10912
1
Do you know where it is failing? Does it manage to send the request? Is it just failing to display the results? Any log outputs from the web browser or client?
– Cameron Downer
Nov 24 '18 at 16:15
yes, it gives error here. 256 | 257 | handleSubmit(event) { 258 | event.preventDefault(); > 259 | this.props.form.validateFields((err, values) => { 260 | if (!err) { 261 | const searchRequest = Object.assign({}, values); 262 | searchModes(0,50)
– chk.buddi
Nov 24 '18 at 16:18
That error isn't making a lot of sense to me. Are you sure that's the full & correct output? Add it to your question if it helps with formatting.
– Cameron Downer
Nov 24 '18 at 16:46
Hi @CameronDowner, I added the error page that displayed when clicking the button
– chk.buddi
Nov 24 '18 at 16:50
The error you're getting isn't to do with the request. You are trying to callthis.props.form.validateFields
butthis.props.form
doesn't exist. You need to look into where you expect theform
prop to come from.I think this question is too broad and I'm going to vote to close, but ask another question if you have a more specific issue
– Cameron Downer
Nov 24 '18 at 17:05
add a comment |
1
Do you know where it is failing? Does it manage to send the request? Is it just failing to display the results? Any log outputs from the web browser or client?
– Cameron Downer
Nov 24 '18 at 16:15
yes, it gives error here. 256 | 257 | handleSubmit(event) { 258 | event.preventDefault(); > 259 | this.props.form.validateFields((err, values) => { 260 | if (!err) { 261 | const searchRequest = Object.assign({}, values); 262 | searchModes(0,50)
– chk.buddi
Nov 24 '18 at 16:18
That error isn't making a lot of sense to me. Are you sure that's the full & correct output? Add it to your question if it helps with formatting.
– Cameron Downer
Nov 24 '18 at 16:46
Hi @CameronDowner, I added the error page that displayed when clicking the button
– chk.buddi
Nov 24 '18 at 16:50
The error you're getting isn't to do with the request. You are trying to callthis.props.form.validateFields
butthis.props.form
doesn't exist. You need to look into where you expect theform
prop to come from.I think this question is too broad and I'm going to vote to close, but ask another question if you have a more specific issue
– Cameron Downer
Nov 24 '18 at 17:05
1
1
Do you know where it is failing? Does it manage to send the request? Is it just failing to display the results? Any log outputs from the web browser or client?
– Cameron Downer
Nov 24 '18 at 16:15
Do you know where it is failing? Does it manage to send the request? Is it just failing to display the results? Any log outputs from the web browser or client?
– Cameron Downer
Nov 24 '18 at 16:15
yes, it gives error here. 256 | 257 | handleSubmit(event) { 258 | event.preventDefault(); > 259 | this.props.form.validateFields((err, values) => { 260 | if (!err) { 261 | const searchRequest = Object.assign({}, values); 262 | searchModes(0,50)
– chk.buddi
Nov 24 '18 at 16:18
yes, it gives error here. 256 | 257 | handleSubmit(event) { 258 | event.preventDefault(); > 259 | this.props.form.validateFields((err, values) => { 260 | if (!err) { 261 | const searchRequest = Object.assign({}, values); 262 | searchModes(0,50)
– chk.buddi
Nov 24 '18 at 16:18
That error isn't making a lot of sense to me. Are you sure that's the full & correct output? Add it to your question if it helps with formatting.
– Cameron Downer
Nov 24 '18 at 16:46
That error isn't making a lot of sense to me. Are you sure that's the full & correct output? Add it to your question if it helps with formatting.
– Cameron Downer
Nov 24 '18 at 16:46
Hi @CameronDowner, I added the error page that displayed when clicking the button
– chk.buddi
Nov 24 '18 at 16:50
Hi @CameronDowner, I added the error page that displayed when clicking the button
– chk.buddi
Nov 24 '18 at 16:50
The error you're getting isn't to do with the request. You are trying to call
this.props.form.validateFields
but this.props.form
doesn't exist. You need to look into where you expect the form
prop to come from.I think this question is too broad and I'm going to vote to close, but ask another question if you have a more specific issue– Cameron Downer
Nov 24 '18 at 17:05
The error you're getting isn't to do with the request. You are trying to call
this.props.form.validateFields
but this.props.form
doesn't exist. You need to look into where you expect the form
prop to come from.I think this question is too broad and I'm going to vote to close, but ask another question if you have a more specific issue– Cameron Downer
Nov 24 '18 at 17:05
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53459119%2fhow-to-load-data-by-submitting-value-in-react-app%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53459119%2fhow-to-load-data-by-submitting-value-in-react-app%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Do you know where it is failing? Does it manage to send the request? Is it just failing to display the results? Any log outputs from the web browser or client?
– Cameron Downer
Nov 24 '18 at 16:15
yes, it gives error here. 256 | 257 | handleSubmit(event) { 258 | event.preventDefault(); > 259 | this.props.form.validateFields((err, values) => { 260 | if (!err) { 261 | const searchRequest = Object.assign({}, values); 262 | searchModes(0,50)
– chk.buddi
Nov 24 '18 at 16:18
That error isn't making a lot of sense to me. Are you sure that's the full & correct output? Add it to your question if it helps with formatting.
– Cameron Downer
Nov 24 '18 at 16:46
Hi @CameronDowner, I added the error page that displayed when clicking the button
– chk.buddi
Nov 24 '18 at 16:50
The error you're getting isn't to do with the request. You are trying to call
this.props.form.validateFields
butthis.props.form
doesn't exist. You need to look into where you expect theform
prop to come from.I think this question is too broad and I'm going to vote to close, but ask another question if you have a more specific issue– Cameron Downer
Nov 24 '18 at 17:05